import requests
from bs4 import BeautifulSoup
'''
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.chrome.options import Options

options = Options
options.page_load_strategy = 'eager'
browser = webdriver.Chrome(options=options)

'''

def req(url, paramsvalue=None, datavalue=None, dire=True):
    headersvalue = {'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/100.0.4896.127 Safari/537.36 Edg/100.0.1185.44',}
    if dire:
        r = requests.get(url, headers=headersvalue, params=paramsvalue)
    else:
        r = requests.post(url, headers=headersvalue, data=datavalue)
    soup = BeautifulSoup(r.text, 'lxml')
    return soup

def bd2020(movie):
    soup = req('https://www.bd2020.co/search.jspx', paramsvalue={'q': movie})
    node_div = soup.find('div', class_='dfg-video-list list')('div', class_='text-overflow')
    results = [(div.a.string, div.a['href']) for div in node_div if div.a != None]       # node_div 中有不想要的 div 节点（因为有多值div属性），所以加上 if 判断
    p_results = ['title：{}，url：{}'.format(result[0], result[1]) for result in results if result[0].find(movie) != -1]          # 网站的搜索结果不太准确，筛选一下
    print('{}\nBD影视分享 的搜索结果：\n{}'.format('='*110, '\n'.join(p_results)))

def haokongbu(movie):
    soup = req('https://s.haokongbu1.com/e/search/', datavalue={'show': 'title,ftitle,actor', 'keyboard': movie}, dire=False)
    node_li = soup.find('div', class_='channel-content')('li')
    results = [(li.p.a.string, li.p.a['href']) for li in node_li]
    p_results = ['title：{}，url：{}'.format(result[0], result[1]) for result in results if result[0].find(movie) != -1]
    print('{}\n好恐怖 的搜索结果：\n{}'.format('='*110, '\n'.join(p_results)))

def search():
    movie = input('输入需要搜索的影视名：')
    bd2020(movie)
    haokongbu(movie)

search()